/*
 * @Description: 步进电机驱动程序(28BYJ-48)
 * @Author: diyhome
 * @Gitee: https://gitee.com/jingjiangxueyuan_hmqs
 * @Date: 2019-12-24 15:17:56
 * @LastEditors  : diyhome
 * @LastEditTime : 2019-12-24 16:19:30
 */
#ifndef __STEPMOTOR_H__
#define __STEPMOTOR_H__
#include "main.h"

// 定义一个结构体储存步进电机的变量
typedef struct Motor
{
    volatile uint16_t Motor_A;
    volatile uint16_t Motor_B;
    volatile uint16_t Motor_C;
    volatile uint16_t Motor_D;

    volatile int direction;
    volatile uint16_t Motor_Pulse;
} Motor;

/**
 * @description: 计算电机控制脉冲
 * @param {type} 角度
 * @return: 脉冲量
 */
int Motor_Angle_Cal(Motor *mo, int Rotition_Angle);
/**
 * @description: 电机8节拍控制
 * @param {type} step:步数; *mo:Motor结构体; *gpioGroup:对应引脚属于第几组
 */
void Motor_CONTROLD(uint8_t step, Motor *mo, GPIO_TypeDef *gp);
// 关闭电机
void CloseMotor(GPIO_TypeDef *gp, Motor *mo);
// 初始化函数
void INIT_Motor(Motor *mo, uint16_t A, uint16_t B, uint16_t C, uint16_t D);
#endif